<template>
  <div class="chart-container" ref="pieChart" style="width: 100%; height: 100%"></div>
</template>

<script setup>
import * as echarts from "echarts";
import { ref, onMounted } from "vue";

const pieChart = ref(null);
let myChart = null;
const teaData = [
  { name: '华南地区', value: 73.76, itemStyle: { color: '#5470c6' } },
  { name: '西南地区', value: 113.00, itemStyle: { color: '#91cc75' } },
  { name: '江南地区', value: 34.00, itemStyle: { color: '#fac858' } },
  { name: '江北地区', value: 35.70, itemStyle: { color: '#ee6666' } }
];

onMounted(() => {
  myChart = echarts.init(pieChart.value, null, { // 去除背景颜色
    renderer: "canvas",
    useDirtyRect: false,
  });

  const option = {
    title: {
      text: '2025全国地区产茶分布',
      left: 'center',
      textStyle: {
        color: '#32ccee',
        fontSize: 16
      }
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'shadow'
      },
      formatter: '{b}: {c}万吨'
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: {
      type: 'category',
      data: teaData.map(item => item.name),
      axisLabel: {
        color: '#FFF',
        fontSize: 12
      },
      axisLine: {
        lineStyle: {
          color: '#FFF'
        }
      }
    },
    yAxis: {
      type: 'value',
      name: '产量（万吨）',
      nameTextStyle: {
        color: '#FFF'
      },
      axisLabel: {
        color: '#FFF',
        fontSize: 12
      },
      axisLine: {
        lineStyle: {
          color: '#FFF'
        }
      },
      splitLine: {
        lineStyle: {
          color: 'rgba(255, 255, 255, 0.1)'
        }
      }
    },
    series: [
      {
        name: '茶叶产量',
        type: 'bar',
        data: teaData.map(item => ({
          value: item.value,
          itemStyle: item.itemStyle
        })),
        barWidth: '40%',
        itemStyle: {
          borderRadius: [5, 5, 0, 0]
        },
        label: {
          show: true,
          position: 'top',
          color: '#FFF',
          formatter: '{c}万吨'
        },
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  };

  myChart.setOption(option);
  window.addEventListener("resize", myChart.resize);
});
</script>

<style scoped>
.chart-container {
  width: 100%;
  height: 320px;
  
  background: rgba(0, 20, 50, 0.5);
  border-radius: 8px;
  padding: 10px;
  position: relative;
}

</style> 